#define _CRT_SECURE_NO_WARNINGS 1
typedef struct {

	int* a;
	int rear;
	int front;
	int k;

} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {

	MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
	obj->a = (int*)malloc(sizeof(int) * (k + 1));
	obj->rear = 0;
	obj->front = 0;
	obj->k = k;

	return obj;

}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {

	return (obj->rear == obj->front);

}

bool myCircularQueueIsFull(MyCircularQueue* obj) {

	return ((obj->rear + 1) % (obj->k + 1) == obj->front);

}
//向循环队列插入一个元素。如果成功插入则返回真。
bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {

	if (myCircularQueueIsFull(obj))
		return false;

	obj->a[obj->rear] = value;
	obj->rear++;
	obj->rear = (obj->rear) % (obj->k + 1);

	return true;

}
//从循环队列中删除一个元素。如果成功删除则返回真
bool myCircularQueueDeQueue(MyCircularQueue* obj) {

	if (myCircularQueueIsEmpty(obj))
		return false;

	obj->front++;
	obj->front = obj->front % (obj->k + 1);
	return true;



}
//从队首获取元素。如果队列为空，返回 -1 。
int myCircularQueueFront(MyCircularQueue* obj) {

	if (myCircularQueueIsEmpty(obj))
		return -1;

	else

		return obj->a[obj->front];


}
//获取队尾元素。如果队列为空，返回 -1 。
int myCircularQueueRear(MyCircularQueue* obj) {

	if (myCircularQueueIsEmpty(obj))
		return -1;

	else
	{
		return obj->a[(obj->rear == 0 ? obj->k : obj->rear - 1)];
	}



}



void myCircularQueueFree(MyCircularQueue* obj) {

	free(obj->a);
	free(obj);

}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/